package com.example.budget3.modify;


import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.budget3.R;

@SuppressLint("SimpleDateFormat")
public class TimeViewAdapter extends BaseAdapter {

    private final String mButtonNames [];           // Text on buttons

    private final LayoutInflater mInflater;

    public TimeViewAdapter(Context context) {
        super();
        mButtonNames = context.getResources().getStringArray(R.array.time_buttons_list);
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return  mButtonNames.length;// mButtonNames.length;
    }

    @Override
    public Object getItem(int position) {
        if (position < mButtonNames.length) {
            return mButtonNames[position];
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View v;
        // Check if can recycle the view
        if (convertView == null || ((Integer) convertView.getTag()).intValue() != R.layout.pulldown_period_selector_button) {
            v = mInflater.inflate(R.layout.pulldown_period_selector_button, parent, false);
            v.setTag(Integer.valueOf(R.layout.pulldown_period_selector_button));
        } else {
            v = convertView;
        }
        TextView date = (TextView) v.findViewById(R.id.period_button);
        date.setText(mButtonNames[position]);
        return v;
    }

    @Override
    public boolean isEmpty() {
        return (mButtonNames.length == 0);
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {

	        View v = mInflater.inflate(R.layout.pulldown_period_selector_item, parent, false);
	        TextView viewType = (TextView)v.findViewById(R.id.period_item);
	        viewType.setText(mButtonNames [position]);    
	        return v;
        
    }


}
